#include "GRO_Gui.h"


namespace GRO
{

void OpenPanel(Panel* panel)
{
    if(panel != NULL)
        panel->open();
}

/*void ClosePanel(Panel* panel)
{
    if(panel != NULL)
        panel->close();
}*/

void ScrollMinus(ScrollBar* bar, Widget* container)
{
    if(bar != NULL/* && container != NULL*/ && bar->value > 0)
    {
        switch(bar->direction)
        {
            case UP:
            case DOWN:
                //bar->scroll -= container->area.h/20;
                bar->value -= bar->increment;//bar->area.h/20;
            break;
            case LEFT:
            case RIGHT:
                //bar->scroll -= container->area.w/20;
                bar->value -= bar->increment;//bar->area.w/20;
            break;
        }
        if(bar->value < 0)
            bar->value = 0;
    }
}

void ScrollPlus(ScrollBar* bar, Widget* container)
{
    if(bar != NULL/* && container != NULL*/)
    {
        bar->value += bar->increment;
        if(bar->value > 1)
            bar->value = 1;
    }
}

void ScrollMouseWheel(ScrollBar* bar, bool up)
{
    if(bar == NULL)
        return;
    if(up)
        bar->minus.onClick.emit();
    else
        bar->plus.onClick.emit();
}

void ListBoxScroll(ListBox* box, bool up)
{
    if(box == NULL)
        return;
    if(up)
        box->scrollY.minus.onClick.emit();
    else
        box->scrollY.plus.onClick.emit();
}

void SpinnerMinus(Spinner* spinner)
{
    if(spinner != NULL)
    {
        spinner->value -= spinner->increment;
        if(spinner->value < spinner->min)
            spinner->value = spinner->min;
    }
}
void SpinnerPlus(Spinner* spinner)
{
    if(spinner != NULL)
    {
        spinner->value += spinner->increment;
        if(spinner->value > spinner->max)
            spinner->value = spinner->max;
    }
}

void SetString(string* str, const char* value)
{
    if(str != NULL)
        *str = value;
}


/*
int MenuCallback(Button* item, Widget* widget, int user)
{
    Panel* menu = static_cast<Panel*>(widget);
    if(menu == NULL || item == NULL)
        return 0;
    menu->area.x = item->area.x;
    menu->area.y = item->area.y + item->area.h;
    if(menu->folded)
        menu->open();
    else
        menu->close();
    return 0;
}*/
}


